package com.profound.blog.dao;

import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


public class SessionUtil {
	
	private static SqlSessionFactory factory = null;

	static{
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		Reader reader;
		try {
			reader = Resources.getResourceAsReader("mybatis-config.xml");
			factory = builder.build(reader);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public static SqlSession getSession(){
		SqlSession s = null;
		s = factory.openSession(); 
		return s;
	}
	public static void main(String[] args) {
		SqlSession s = getSession();
		System.out.println(s);
		s.close();
	}
	
}
